package com.game.code;

import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;

import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.joints.PrismaticJointDef;



public class Platform {

	public static final float WORLD_PHYSICS_SIZE = 10;

	public static final float PLATFORM_PHYSICS_WIDTH = WORLD_PHYSICS_SIZE/10;
	public static final float PLATFORM_PHYSICS_HEIGHT = WORLD_PHYSICS_SIZE/50;

	public static final float PLATFORM_PHYSICS_Y_COORD = WORLD_PHYSICS_SIZE/3;
	
	Body body;
	
	public Platform(World world) {

		//ground
		BodyDef ground_bd = new BodyDef();
		Body ground = world.createBody(ground_bd);
		
		//platform
		BodyDef platform_bd = new BodyDef();
	    platform_bd.type = BodyType.DYNAMIC;
	    platform_bd.position.set(0.0f, PLATFORM_PHYSICS_Y_COORD);

	    body = world.createBody(platform_bd);

	    PolygonShape platform_shape = new PolygonShape();
		platform_shape.setAsBox(PLATFORM_PHYSICS_WIDTH, PLATFORM_PHYSICS_HEIGHT);
		
		FixtureDef platform_fd = new FixtureDef();
		platform_fd.shape = platform_shape;
		//platform_fd.friction = 0.6f;
		platform_fd.density = 0.2f;
		platform_fd.friction=0;
		platform_fd.restitution = 0.0f;

		body.createFixture(platform_fd);
		
		
		PrismaticJointDef pjd = new PrismaticJointDef();

		pjd.initialize(ground, body, new Vec2(0.0f, PLATFORM_PHYSICS_Y_COORD), new Vec2(1.0f, 0.0f));
		
		//pjd.maxMotorForce = 1000.0f;
		//pjd.enableMotor = true;
		pjd.lowerTranslation = -(WORLD_PHYSICS_SIZE/2-PLATFORM_PHYSICS_WIDTH)+WORLD_PHYSICS_SIZE/100;
		pjd.upperTranslation = (WORLD_PHYSICS_SIZE/2-PLATFORM_PHYSICS_WIDTH) -WORLD_PHYSICS_SIZE/100;
		pjd.enableLimit = true;
		
		world.createJoint(pjd);
	}

	
	
}
